package cn.neusoft.service.impl;


import cn.neusoft.domain.Warehouse;
import cn.neusoft.mapper.WarehouseMapper;
import cn.neusoft.service.WarehouseAdministrateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
@Service

public class WarehouseAdministrateImp implements WarehouseAdministrateService {

    @Autowired
    private WarehouseMapper warehouseMapper;

    @Override
    public int warehouseRegister(Warehouse warehouse) {
        int ans = 0;

        if(warehouse != null){
            if(warehouseMapper.findByName(warehouse.getName()) == null){
                warehouseMapper.insert(warehouse);
            }

        }

        return ans;
    }

    @Override
    public int warehouseDelete(String name) {
        int ans = 0;

        if(name != null){
            ans = warehouseMapper.deleteByName(name);
        }

        return ans;
    }

    @Override
    public int warehouseChange(Warehouse warehouse) {
        int ans = 0;

        if(warehouse != null){
            ans = warehouseMapper.update(warehouse);
        }

        return ans;
    }

    @Override
    public List<Warehouse> warehouseGetAll() {
        List<Warehouse> list = null;

        list = warehouseMapper.getAll();

        return list;
    }

    @Override
    public Warehouse getWarehouseByID(int id) {
        return warehouseMapper.findByID(id);
    }

    @Override
    public int warehouseDeleteByID(int id) {
        return warehouseMapper.deleteByIdInt(id);
    }
}
